<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - ormqr.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2010  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_LAPACk_ORMQR_Hh_
<font color='#0000FF'>#define</font> DLIB_LAPACk_ORMQR_Hh_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='fortran_id.h.html'>fortran_id.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>
    <font color='#0000FF'>namespace</font> lapack
    <b>{</b>
        <font color='#0000FF'>namespace</font> binding
        <b>{</b>
            <font color='#0000FF'>extern</font> "<font color='#CC0000'>C</font>"
            <b>{</b>
                <font color='#0000FF'><u>void</u></font> <b><a name='DLIB_FORTRAN_ID'></a>DLIB_FORTRAN_ID</b><font face='Lucida Console'>(</font>dormqr<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>char</u></font> <font color='#5555FF'>*</font>side, <font color='#0000FF'><u>char</u></font> <font color='#5555FF'>*</font>trans, integer <font color='#5555FF'>*</font>m, integer <font color='#5555FF'>*</font>n, 
                                              integer <font color='#5555FF'>*</font>k, <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>a, integer <font color='#5555FF'>*</font>lda, <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>tau, 
                                              <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font> c_, integer <font color='#5555FF'>*</font>ldc, <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>work, integer <font color='#5555FF'>*</font>lwork, 
                                              integer <font color='#5555FF'>*</font>info<font face='Lucida Console'>)</font>;

                <font color='#0000FF'><u>void</u></font> <b><a name='DLIB_FORTRAN_ID'></a>DLIB_FORTRAN_ID</b><font face='Lucida Console'>(</font>sormqr<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>char</u></font> <font color='#5555FF'>*</font>side, <font color='#0000FF'><u>char</u></font> <font color='#5555FF'>*</font>trans, integer <font color='#5555FF'>*</font>m, integer <font color='#5555FF'>*</font>n, 
                                              integer <font color='#5555FF'>*</font>k, <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>a, integer <font color='#5555FF'>*</font>lda, <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>tau, 
                                              <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font> c_, integer <font color='#5555FF'>*</font>ldc, <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>work, integer <font color='#5555FF'>*</font>lwork, 
                                              integer <font color='#5555FF'>*</font>info<font face='Lucida Console'>)</font>;

            <b>}</b>

            <font color='#0000FF'>inline</font> <font color='#0000FF'><u>int</u></font> <b><a name='ormqr'></a>ormqr</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>char</u></font> side, <font color='#0000FF'><u>char</u></font> trans, integer m, integer n, 
                              integer k, <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>a, integer lda, <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>tau, 
                              <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>c_, integer ldc, <font color='#0000FF'><u>double</u></font> <font color='#5555FF'>*</font>work, integer lwork<font face='Lucida Console'>)</font>
            <b>{</b>
                integer info <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#BB00BB'>DLIB_FORTRAN_ID</font><font face='Lucida Console'>(</font>dormqr<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>side, <font color='#5555FF'>&amp;</font>trans, <font color='#5555FF'>&amp;</font>m, <font color='#5555FF'>&amp;</font>n,
                                        <font color='#5555FF'>&amp;</font>k, a, <font color='#5555FF'>&amp;</font>lda, tau,
                                        c_, <font color='#5555FF'>&amp;</font>ldc, work, <font color='#5555FF'>&amp;</font>lwork, <font color='#5555FF'>&amp;</font>info<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> info;
            <b>}</b>

            <font color='#0000FF'>inline</font> <font color='#0000FF'><u>int</u></font> <b><a name='ormqr'></a>ormqr</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>char</u></font> side, <font color='#0000FF'><u>char</u></font> trans, integer m, integer n, 
                              integer k, <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>a, integer lda, <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>tau, 
                              <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>c_, integer ldc, <font color='#0000FF'><u>float</u></font> <font color='#5555FF'>*</font>work, integer lwork<font face='Lucida Console'>)</font>
            <b>{</b>
                integer info <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#BB00BB'>DLIB_FORTRAN_ID</font><font face='Lucida Console'>(</font>sormqr<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>side, <font color='#5555FF'>&amp;</font>trans, <font color='#5555FF'>&amp;</font>m, <font color='#5555FF'>&amp;</font>n,
                                        <font color='#5555FF'>&amp;</font>k, a, <font color='#5555FF'>&amp;</font>lda, tau,
                                        c_, <font color='#5555FF'>&amp;</font>ldc, work, <font color='#5555FF'>&amp;</font>lwork, <font color='#5555FF'>&amp;</font>info<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> info;
            <b>}</b>



        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
<font color='#009900'>/*  -- LAPACK routine (version 3.1) -- */</font>
<font color='#009900'>/*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */</font>
<font color='#009900'>/*     November 2006 */</font>

<font color='#009900'>/*     .. Scalar Arguments .. */</font>
<font color='#009900'>/*     .. */</font>
<font color='#009900'>/*     .. Array Arguments .. */</font>
<font color='#009900'>/*     .. */</font>

<font color='#009900'>/*  Purpose */</font>
<font color='#009900'>/*  ======= */</font>

<font color='#009900'>/*  DORMQR overwrites the general real M-by-N matrix C with */</font>

<font color='#009900'>/*                  SIDE = 'L'     SIDE = 'R' */</font>
<font color='#009900'>/*  TRANS = 'N':      Q * C          C * Q */</font>
<font color='#009900'>/*  TRANS = 'T':      Q**T * C       C * Q**T */</font>

<font color='#009900'>/*  where Q is a real orthogonal matrix defined as the product of k */</font>
<font color='#009900'>/*  elementary reflectors */</font>

<font color='#009900'>/*        Q = H(1) H(2) . . . H(k) */</font>

<font color='#009900'>/*  as returned by DGEQRF. Q is of order M if SIDE = 'L' and of order N */</font>
<font color='#009900'>/*  if SIDE = 'R'. */</font>

<font color='#009900'>/*  Arguments */</font>
<font color='#009900'>/*  ========= */</font>

<font color='#009900'>/*  SIDE    (input) CHARACTER*1 */</font>
<font color='#009900'>/*          = 'L': apply Q or Q**T from the Left; */</font>
<font color='#009900'>/*          = 'R': apply Q or Q**T from the Right. */</font>

<font color='#009900'>/*  TRANS   (input) CHARACTER*1 */</font>
<font color='#009900'>/*          = 'N':  No transpose, apply Q; */</font>
<font color='#009900'>/*          = 'T':  Transpose, apply Q**T. */</font>

<font color='#009900'>/*  M       (input) INTEGER */</font>
<font color='#009900'>/*          The number of rows of the matrix C. M &gt;= 0. */</font>

<font color='#009900'>/*  N       (input) INTEGER */</font>
<font color='#009900'>/*          The number of columns of the matrix C. N &gt;= 0. */</font>

<font color='#009900'>/*  K       (input) INTEGER */</font>
<font color='#009900'>/*          The number of elementary reflectors whose product defines */</font>
<font color='#009900'>/*          the matrix Q. */</font>
<font color='#009900'>/*          If SIDE = 'L', M &gt;= K &gt;= 0; */</font>
<font color='#009900'>/*          if SIDE = 'R', N &gt;= K &gt;= 0. */</font>

<font color='#009900'>/*  A       (input) DOUBLE PRECISION array, dimension (LDA,K) */</font>
<font color='#009900'>/*          The i-th column must contain the vector which defines the */</font>
<font color='#009900'>/*          elementary reflector H(i), for i = 1,2,...,k, as returned by */</font>
<font color='#009900'>/*          DGEQRF in the first k columns of its array argument A. */</font>
<font color='#009900'>/*          A is modified by the routine but restored on exit. */</font>

<font color='#009900'>/*  LDA     (input) INTEGER */</font>
<font color='#009900'>/*          The leading dimension of the array A. */</font>
<font color='#009900'>/*          If SIDE = 'L', LDA &gt;= max(1,M); */</font>
<font color='#009900'>/*          if SIDE = 'R', LDA &gt;= max(1,N). */</font>

<font color='#009900'>/*  TAU     (input) DOUBLE PRECISION array, dimension (K) */</font>
<font color='#009900'>/*          TAU(i) must contain the scalar factor of the elementary */</font>
<font color='#009900'>/*          reflector H(i), as returned by DGEQRF. */</font>

<font color='#009900'>/*  C       (input/output) DOUBLE PRECISION array, dimension (LDC,N) */</font>
<font color='#009900'>/*          On entry, the M-by-N matrix C. */</font>
<font color='#009900'>/*          On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */</font>

<font color='#009900'>/*  LDC     (input) INTEGER */</font>
<font color='#009900'>/*          The leading dimension of the array C. LDC &gt;= max(1,M). */</font>

<font color='#009900'>/*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */</font>
<font color='#009900'>/*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */</font>

<font color='#009900'>/*  LWORK   (input) INTEGER */</font>
<font color='#009900'>/*          The dimension of the array WORK. */</font>
<font color='#009900'>/*          If SIDE = 'L', LWORK &gt;= max(1,N); */</font>
<font color='#009900'>/*          if SIDE = 'R', LWORK &gt;= max(1,M). */</font>
<font color='#009900'>/*          For optimum performance LWORK &gt;= N*NB if SIDE = 'L', and */</font>
<font color='#009900'>/*          LWORK &gt;= M*NB if SIDE = 'R', where NB is the optimal */</font>
<font color='#009900'>/*          blocksize. */</font>

<font color='#009900'>/*          If LWORK = -1, then a workspace query is assumed; the routine */</font>
<font color='#009900'>/*          only calculates the optimal size of the WORK array, returns */</font>
<font color='#009900'>/*          this value as the first entry of the WORK array, and no error */</font>
<font color='#009900'>/*          message related to LWORK is issued by XERBLA. */</font>

<font color='#009900'>/*  INFO    (output) INTEGER */</font>
<font color='#009900'>/*          = 0:  successful exit */</font>
<font color='#009900'>/*          &lt; 0:  if INFO = -i, the i-th argument had an illegal value */</font>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T, 
            <font color='#0000FF'><u>long</u></font> NR1, <font color='#0000FF'><u>long</u></font> NR2, <font color='#0000FF'><u>long</u></font> NR3,
            <font color='#0000FF'><u>long</u></font> NC1, <font color='#0000FF'><u>long</u></font> NC2, <font color='#0000FF'><u>long</u></font> NC3,
            <font color='#0000FF'>typename</font> MM,
            <font color='#0000FF'>typename</font> C_LAYOUT
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>int</u></font> <b><a name='ormqr'></a>ormqr</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>char</u></font> side, 
            <font color='#0000FF'><u>char</u></font> trans,
            <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font>T,NR1,NC1,MM,column_major_layout<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> a,
            <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font>T,NR2,NC2,MM,column_major_layout<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> tau,
            matrix<font color='#5555FF'>&lt;</font>T,NR3,NC3,MM,C_LAYOUT<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> c 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> c.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> c.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> a.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> ldc;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_same_type<font color='#5555FF'>&lt;</font>C_LAYOUT,column_major_layout<font color='#5555FF'>&gt;</font>::value<font face='Lucida Console'>)</font>
            <b>{</b>
                ldc <font color='#5555FF'>=</font> c.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#009900'>// Since lapack expects c to be in column major layout we have to 
</font>                <font color='#009900'>// do something to make this work.  Since a row major layout matrix
</font>                <font color='#009900'>// will look just like a transposed C we can just swap a few things around.
</font>
                ldc <font color='#5555FF'>=</font> c.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>m,n<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>side <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>L</font>'<font face='Lucida Console'>)</font>
                    side <font color='#5555FF'>=</font> '<font color='#FF0000'>R</font>';
                <font color='#0000FF'>else</font>
                    side <font color='#5555FF'>=</font> '<font color='#FF0000'>L</font>';

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>trans <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>T</font>'<font face='Lucida Console'>)</font>
                    trans <font color='#5555FF'>=</font> '<font color='#FF0000'>N</font>';
                <font color='#0000FF'>else</font>
                    trans <font color='#5555FF'>=</font> '<font color='#FF0000'>T</font>';
            <b>}</b>

            matrix<font color='#5555FF'>&lt;</font>T,<font color='#979000'>0</font>,<font color='#979000'>1</font>,MM,column_major_layout<font color='#5555FF'>&gt;</font> work;

            <font color='#009900'>// figure out how big the workspace needs to be.
</font>            T work_size <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
            <font color='#0000FF'><u>int</u></font> info <font color='#5555FF'>=</font> binding::<font color='#BB00BB'>ormqr</font><font face='Lucida Console'>(</font>side, trans, m, n, 
                                      k, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, a.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>tau</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>,
                                      <font color='#5555FF'>&amp;</font><font color='#BB00BB'>c</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, ldc, <font color='#5555FF'>&amp;</font>work_size, <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> info;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>work.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> work_size<font face='Lucida Console'>)</font>
                work.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>work_size<font face='Lucida Console'>)</font>, <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// compute the actual result 
</font>            info <font color='#5555FF'>=</font> binding::<font color='#BB00BB'>ormqr</font><font face='Lucida Console'>(</font>side, trans, m, n, 
                                  k, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, a.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>tau</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>,
                                  <font color='#5555FF'>&amp;</font><font color='#BB00BB'>c</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, ldc, <font color='#5555FF'>&amp;</font><font color='#BB00BB'>work</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, work.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>return</font> info;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
    <b>}</b>

<b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_LAPACk_ORMQR_Hh_
</font>

</pre></body></html>